package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.vo.DishVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.domain.Sort;

import java.time.LocalDateTime;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;

public interface OrderMapper {

    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    void update(Orders orders);

    void insert(Orders orders);

    List<OrderVO> getHistoryOrders(Long user_id, Integer status);

    @Select("select * from orders where id = #{id}")
    OrderVO getOrderDetail(Long id);

    @Update("update orders set status = #{status} , cancel_time = #{cancelTime},cancel_reason = #{cancelReason} where id = #{id}")
    void cancel(Orders orders);

    List<OrderVO> conditionSearch(LocalDateTime beginTime, LocalDateTime endTime, String number, String phone, Integer status);

    @Select("select count(*) from orders where status = #{status}")
    Integer countToBeConfirmed(Integer status);

    @Update("update orders set status = #{status} where id = #{id}")
    void confirm(OrdersConfirmDTO orders);

    @Update("update orders set status = #{status} , cancel_time = #{cancelTime} , rejection_reason = #{rejectionReason} where id = #{id}")
    void rejection(Orders orders);

    @Update("update orders set status = #{status} , rejection_reason = #{rejectionReason} where id = #{id}")
    void updateCancel(Orders order);

    @Update("update orders set status = #{status} where id = #{id}")
    void delivery(Orders orders);

    @Update("update orders set status = #{status} , delivery_time = #{deliveryTime} where id = #{id}")
    void complete(Orders orders);

    @Select("select * from orders where status = #{status} and order_time < #{localDateTime}")
    List<Orders> selectByStatusAndOrderTime(Integer status, LocalDateTime localDateTime);

    Double turnoverStatistics(Map map);

    Integer countByMap(Map map);


    List<GoodsSalesDTO> top10(Map map);

    Double sumNumber(Map map);
}
